package byteStream;
/*
字节流:{接口: inputStream:
            outputStream }
FileInputStream继承inputStream:使用read(),读取文件
FileOutputStream继承outputStream:使用write(),写入
字节缓冲流:对普通流进行包装,本身不具有读写能力
 BufferedInputStream:
 BufferedOutputStream:
 */

import java.io.*;
import java.nio.charset.StandardCharsets;

//文件拷贝
public class ByteDemo {
    public static void main(String[] args) throws IOException{
        method2();


    }
//字节缓冲流
    private static void method2() throws IOException {
        BufferedInputStream bis=new BufferedInputStream(new FileInputStream("D:\\java\\JavaMaterial\\1.jpg"));
        BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream("D:\\java\\JavaMaterial\\picture\\1-2.jpg"));
        byte []bytes=new byte[1024];
        int len;
        while ((len=bis.read(bytes))!=-1){
            bos.write(bytes,0,len);
        }
        bis.close();
        bos.close();
    }
//字节流
    public  static void method1()throws IOException{
        //输入流,读取
        FileInputStream fis=new FileInputStream("D:\\java\\JavaMaterial\\1.jpg");
        //输出流,写操作
        FileOutputStream fos=new FileOutputStream("D:\\java\\JavaMaterial\\picture\\1-1.jpg");
        //读写实现
        byte []byt=new byte[1024];
        int len;
        while ((len=fis.read(byt))!=-1){
            fos.write(byt,0,len);
        }
        //关闭流
        fis.close();
        fos.close();
    }


}
